package akash.java.code;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;

import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;


public class WriteXL
{
    
    public static void main(String[] args){
        WriteXL wxl = new WriteXL();
        wxl.createMSDoc();
    }
 public void createXL(){
      try
    {   
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sheet = wb.createSheet("sheet1");
        XSSFRow row = sheet.createRow(0);
        row.createCell(0).setCellValue(1);
        row.createCell(1).setCellValue("akash");
        
        FileOutputStream out = new FileOutputStream("D:/output.xlsx");
        try
        {
            wb.write(out);
            out.close();
        }
        catch(IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
      
    }
    catch(FileNotFoundException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
 }

 public void createText(){
     try
    {   
         
         BufferedWriter bw = new BufferedWriter(new FileWriter("D:/output.docx"));
         bw.write("hello world");
       
       bw.close();
    }
    catch(IOException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     
 }
 
 public  void createMSDoc() {
     XWPFDocument document = new XWPFDocument();

     XWPFParagraph paragraphOne = document.createParagraph();
     XWPFRun paragraphOneRunOne = paragraphOne.createRun();
     paragraphOneRunOne.setText("Hello world! This is paragraph one!");
     XWPFRun paragraphOneRunTwo = paragraphOne.createRun();
     paragraphOneRunTwo.setText(" More text in paragraph one...");

     XWPFParagraph paragraphTwo = document.createParagraph();
     XWPFRun paragraphTwoRunOne = paragraphTwo.createRun();
     paragraphTwoRunOne.setText("And this is paragraph two.");

     FileOutputStream outStream = null;
     try {
         outStream = new FileOutputStream("D:/newMSDoc.docx");
     } catch (FileNotFoundException e) {
         e.printStackTrace();
     }

     try {
         document.write(outStream);
         outStream.close();
     } catch (FileNotFoundException e) {
         e.printStackTrace();
     } catch (IOException e) {
         e.printStackTrace();
     }
 }
}
